home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
Chipmunk Basic 3.2.8
/
chipmunk-basic quick-ref
< prev
next >
Wrap
Text File
|
1995-12-12
|
11KB
|
264 lines
/*
* chipmunk-basic-3.2.8.sit.hqx
* Quick Reference and FAQ
* Chipmunk Basic is (c) Copyright 1990,1994 Ronald H. Nicholson, Jr.
* ALL RIGHTS RESERVED
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY OF ANY KIND; not even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
Quick Reference for Chipmunk Basic v3.2 - PPC Macintosh version 95Nov
ported by Ronald H. Nicholson, Jr. rhn@netcom.com
- The interpreter includes an dumb old fashioned line number based editor.
(enter a line, delete a line, edit one line at a time).
- Line numbers are required.
- The variable types are long floats, short integers and strings with a
maximum length of 254 characters. Variable names can be up to 31
characters long and are case insensitive.
- Math is done using the built-in double precision IEEE math. Trigonometric
functions are all in radians.
Operators, functions and statements include:
+ - * / ^ mod and or xor not > < >= <= <> =
sqr() log() exp() sin() cos() tan() atn() pi
abs() sgn() int() rnd() peek() val() asc() len()
mid$() right$() left$() str$() chr$()
goto if then else endif gosub return select case
for to step next while wend
rem let dim data read restore field$()
input print open for output append as close# load save
inkey$ input$ eof() files fgetbyte# fseek# fputbyte
run stop end exit quit cont renum new clear def fn
date$ time$ timer push() pop sound morse say sub
cls gotoxy moveto lineto graphics window scrn mouse()
home get htab vtab pos() varptr peek() poke fre
type string integer single double
---
Some Simple Examples:
for i=1 to 10 : print i : next i
c$ = a$ + b$ : rem string concatenation
a$ = inkey$ : rem inkey$ is non-blocking
load "sieve.bas" : rem load TEXT file as a Basic program
: rem file names should have .bas extension
open "filename" for output as #1 : print #1, "hello world" : close #1
gotoxy 5,10 : print "here" : rem text window (0,0 origin)
x = pos(0) : rem text cursor horizontal location
y = pos(-1) : rem vertical text cursor location
graphics 0 : moveto 10,10 : lineto 110,80 : rem draw graphics line
---
Frequently Asked Questions:
Q: Is more documentation on learning how to program in the BASIC language?
A: The language is mostly compatible with books on programming in the BASIC
language that were published between 1978 and 1988. Since these are
mostly out of print, your best bet is to try your local public library.
Q: Is there any way to redirect print statements to the printer?
A: No, there is no way to make this work with current MacOS printer drivers.
I recommend printing to a file, and then using SimpleText to print.
Q: Why can't I load a text file using the "Open" menu?
A: Chipmunk Basic requires that Basic program file names end with a ".bas"
suffix. However, if you hold down the option key, it will try to open any
TEXT file.
Q: How do I talk to the serial ports using Chipmunk Basic?
A: Chipmunk Basic requires that the Communications ToolBox "Serial Tool"
be installed in the Extensions folder in the System Folder. First
open "COM1:" for input, followed by opening "COM1:" for output.
The errorstatus$ string variable will return a string you can use
instead of "COM1:" when you don't want the CTB setup dialog box.
Try the following snippet:
100 rem *** Using the CTB serial ports ***
110 on error goto 190
120 open "COM1:" for input as #3 : alt_setup$ = "COM1: " + errorstatus$
130 open "COM1:" for output as #4
150 while not mouse(0)
160 if not eof(3) then i = fgetbyte(3) : print chr$(i);
170 c$ = inkey$ : if len(c$) > 0 then print #4,c$;
180 wend
190 print " closing serial ports" : close #4 : close #5
Closing and re-opening the port will toggle the handshake line.
THe command 'CALL "sendbreak", n' will send a break for n ticks.
Q: How do I make my own sprites?
A: I use ResEdit (available from ftp.apple.com). Just paste the new sprite
'ICN#' and 'cicn's into the resource fork of your Basic program. Resource
ID's 128-160 are reserved for the Chipmunk Basic interpreter, so please use
a high resource ID number. A 'cicn' resource must have a corresponding
'ICN#' resource in order for Chipmunk Basic to display it.
Q: Why can't I make my graphics window bigger?
If you have enough memory in your Mac, try increasing the Preferred Memory
requirements of Chipmunk Basic using the Finder Get Info dialog. Also try
decreasing the number of colors in the Monitors Control Panel.
Q: Why won't this Microsoft QuickBasic program run? ...
A: Chipmunk Basic was never intended to be exactly compatible with any other
commercial BAISC language product. It does include most of the features of
ANSI BASIC language definition. Many BASIC programs that are saved as
ASCII text files and that don't use features of specific computer systems
can be easily ported to Chipmunk Basic.
Q: Can you send me a list of different peeks and pokes?
A: Peeks and pokes don't have much use on current Mac Systems. If you want to
live dangerously, you might want to get a copy of SysEqu.h or LoMem.h from
an old C or 68K assembly language programming package; but don't expect
anything you do to be compatible with newer MacOS System software.
Q: Is there a compiler for Chipmunk Basic?
A: No, however there are several commercial Basic compilers on the market and
rumors of major new support for the BASIC language on the Mac coming next
year (1996 maybe ?, Kenobi ??, Denali ??? ... ).
Q: What is the history of Chipmunk Basic?
A: In March 1990, p2c, a pascal to c translator was posted to comp.source.misc
by David Gillespie. One of the test input files was "basic.p". I used the
c output file to learn about language interpreters and then ported the
resulting Basic interpreter to my Mac 512KE and then to a PowerMac 7100.
---
Some experimental Chipmunk Basic graphics commands:
* note: The graphics commands in version 3.x are beta test and may be buggy. *
GRAPHICS 0 // show graphics window
graphics -1 // hide graphics window
graphics WINDOW x, y, width, height // graphics window setup
graphics MOVETO x,y // Move pen To x,y
graphics LINETO x,y // draw Line To x,y
graphics OVAL x,y // oval x wide by y high
graphics DRAWTEXT a$ // DrawText
// use MOVETO to position
graphics RECT x1,y1, x2,y2 // FrameRect
graphics FILLRECT x1,y1, x2,y2,pat# // PaintRect
graphics FILLRECT x1,y1, x2,y2,-1 // EraseRect
graphics OVAL x1,y1, x2,y2 // FrameOval
graphics FILLOVAL x1,y1, x2,y2,pat# // PaintOval
graphics PENSETUP xsize, ysize, [ mode, pat# ]
graphics COLOR i // set RGBForeColor by index
graphics COLOR r,g,b // red green blue 0-100
graphics PICT x,y,n // draw 'pict' resource n
graphics TEXTSETUP f, s, m // set up text font, size, mode
graphics (-38) // get graphics window max width
graphics (-39) // get graphics window max height
SPRITE n x, y, id // sprite n @ x,y using ICN# or cicn id
// n from 1 to 15, 1 in frontmost plane
// ICN# 128 - 141 included with app
// a cicn requires ICN# with same id.
sprite n UP x // sprite #n move up x pixels
sprite n DOWN x // also returns new sprite y coord
sprite n LEFT x // move LEFT (not turn as in Logo!)
sprite n RIGHT x
sprite n TURN d // turn CCW d degrees
sprite n FORWARD x // move forward x pixels
sprite n PENUP
sprite n PENDOWN
sprite n COLLISION // returns 1st sprite# in contact
sprite n TO x,y // paste a fixed sprite image at (x,y)
---
Other unusual and/or experimental or beta test features:
morse "CQ DE N6YWU",16,40,13,700 // play morse code
// MORSE string, dot_wpm, volume, letter_wpm, freq
open "SFGetFile" for input as #2 // "SFPutFile" works for output
open "COM1:" for input as #3 // *requires* CTB Serial Tool
open f$ for data input as #4 // data file, no cr-lf translation
open f$ for data input // use file for resources, picts, etc.
say "hello world" // *requires* the Speech Manager & Lib
say "faster", 196, 44, 1 // string, rate, pitch, voice #
a$ = field$("aa bb cc", 2," ") // returns "bb", (awk fields)
sound 440,0.5,30 // freq, secs_duration, vol 0-100
sound 0,8192 // play snd resource 8192
sound -1,a(0),11100 // play 1 sec. of samples from array a
sound -2,midi_voice,midi_key,velocity,secs_dur // quicktime note
sound n,freq(0),dur,vol(0) // play n voices from arrays freq & vol
call "record", a(0), n // records n samples of sound into a
graphics WINDOW -1,-1, x,y, 2 // scroll graphics background
graphics BUTTON title$,x,y,w,h,key_code // draw a standard button
// at location x,y size w,h
// the button will input chr$(key_code) when hit
graphics BUTTON title$,x,y,w,h,varptr(a$)
// the button will execute a$ when pushed
graphics BUTTON "",x,y,w,h,varptr(a$) // transparent button
graphics BUTTON "",x,y,id,key_code,-4 // cicn or ICN# id button
graphics BUTTON "",-1 // remove all buttons
graphics EDIT a$ [,w,h] // edit a$ in a text edit box
call "sendbreak", t // breaks for t ticks on the open serial port
call "hideMenuBar" // graphics -1 restores it
call "beep", i // calls BCMD resource "beep" with 1 long* param
call "doscript", appname$, doscript$ // send a DoScript AE
call "applescript", script$ // compiles and executes a script.
// script$ can also be a string array.
A couple oddball commands included in version 3.2.x just for testing:
call "fft_polar", real(0), amp(0), phase(0) , size // size must 2^n
call "fft_inv", amp(0), phase(0), real(0) , size // inverse fft
call "math$", "mul$", r$, "1234567890", "9876543210"
// 250 digit string math (add$, sub$, mul$, div$, mod$)
- "Preferred Size" from Finder Get Info may limit maximum graphics window size
- ICN#, cicn, PICT & BCMD resources may be stored the resource fork of a file:
open "foo.rsrc" for data input : rem with no "as" token,
// makes the file foo.rsrc the current resource file
- bigfont options are stored in the Prefs file (edit w/ BBEdit or equiv.)
- AppleScript scriptable. Try this script from a script editor:
tell application "chipbasic" to DoScript "print 3+4"
tell application "chipbasic" to DoScript "exec( \" 5 * 7 \" )"
---
Bugs or features:
- All input works like the LINE INPUT statement of other Basic versions.
- Line numbers above 999999999 will not list.
- Other reserved words (don't use!) : break width swap do memstat
draw pset bload bsave class method private public local
- Programs without line numbers can be loaded. However line numbers will
be added. The target of a GOTO can be a label followed by a colon.
---
A sample program:
--- cut here ---
1 rem "sieve.bas" , a prime number sieve benchmark
2 t = timer
3 dim f(8194)
4 for i = 0 to 8191 : f(i) = 1 : next i
5 s = 8191
6 for i = 0 to s
7 if f(i) = 0 then goto 11
8 p = i+i+3
9 for k = i+p to s step p : f(k) = 0 : next k
10 c = c+1
11 next i
12 print c;" primes found in ";
13 t = timer-t
14 print t;" seconds"
15 end
--- cut here ---
*/